@echo off

set httpd_url= https://www.apachelounge.com/download/VS17/binaries/httpd-2.4.63-250207-win64-VS17.zip
set php_url= https://windows.php.net/downloads/releases/php-8.4.8-Win32-vs17-x64.zip

mkdir origin 
curl -o origin/httpd.zip %httpd_url%
curl -o origin/php.zip %php_url%

7z x origin/httpd.zip -o./origin/httpd -y
7z x origin/php.zip -o./origin/php -y

mkdir release\bin
mkdir release\conf
mkdir release\logs
mkdir release\modules
mkdir release\php_ext

copy origin\httpd\Apache24\bin\httpd.exe release\bin
copy origin\httpd\Apache24\bin\libapr-1.dll release\bin
copy origin\httpd\Apache24\bin\libapriconv-1.dll release\bin
copy origin\httpd\Apache24\bin\libaprutil-1.dll release\bin
copy origin\httpd\Apache24\bin\libhttpd.dll release\bin
copy origin\httpd\Apache24\bin\pcre2-8.dll release\bin

copy origin\httpd\Apache24\modules\mod_authz_core.so release\modules
copy origin\httpd\Apache24\modules\mod_autoindex.so release\modules
copy origin\httpd\Apache24\modules\mod_dir.so release\modules
copy origin\httpd\Apache24\modules\mod_log_config.so release\modules
copy origin\httpd\Apache24\modules\mod_mime.so release\modules
copy origin\httpd\Apache24\modules\mod_rewrite.so release\modules
copy origin\httpd\Apache24\modules\mod_ssl.so release\modules

copy origin\httpd\Apache24\conf\mime.types release\conf

copy origin\php\php8apache2_4.dll release\bin
copy origin\php\php8ts.dll release\bin
copy origin\php\php.exe release\bin
copy origin\php\libsqlite3.dll release\bin
copy origin\php\libssh2.dll release\bin
copy origin\php\icu*.dll release\bin
copy origin\php\ext\*.dll release\php_ext

:xml
(
echo ServerRoot "${SRVROOT}"
echo.
echo LoadModule authz_core_module modules/mod_authz_core.so
echo LoadModule log_config_module modules/mod_log_config.so
echo LoadModule rewrite_module modules/mod_rewrite.so
echo LoadModule autoindex_module modules/mod_autoindex.so
echo LoadModule dir_module modules/mod_dir.so
echo LoadModule mime_module modules/mod_mime.so
echo LoadModule php_module bin/php8apache2_4.dll
echo.
echo AddHandler application/x-httpd-php .php
echo PHPIniDir "${SRVROOT}/conf"
echo.
echo Listen 80
echo ServerName localhost
echo ServerAdmin aplite@localhost
echo.
echo ServerTokens Prod
echo ServerSignature Off
echo.
echo ErrorLog "${SRVROOT}/logs/error.log"
echo LogLevel emerg
echo.
echo ^<IfModule log_config_module^>
echo     LogFormat "%%h %%l %%u %%t \"%%r\" %%>s %%b \"%%{Referer}i\" \"%%{User-Agent}i\"" combined
echo     LogFormat "%%h %%l %%u %%t \"%%r\" %%>s %%b" common
echo     ^<IfModule logio_module^>
echo       LogFormat "%%h %%l %%u %%t \"%%r\" %%>s %%b \"%%{Referer}i\" \"%%{User-Agent}i\" %%I %%O" combinedio
echo     ^</IfModule^>
echo     CustomLog "logs/access.log" common
echo ^</IfModule^>
echo.
echo ^<VirtualHost 0.0.0.0:80^>
echo     DocumentRoot "${SRVROOT}/htdocs"
echo     DirectoryIndex index.html index.php
echo     ^<Directory "${SRVROOT}/htdocs"^>
echo         Options Indexes FollowSymLinks MultiViews
echo         AllowOverride All
echo     ^</Directory^>
echo     ErrorLog "${SRVROOT}/logs/aplite-error.log"
echo     CustomLog "${SRVROOT}/logs/aplite-access.log" common
echo ^</VirtualHost^>
)>release/conf/aplite.conf

:xml
(
echo [PHP]
echo expose_php = Off
echo.
echo extension_dir="..\\php_ext"
echo extension=bz2
echo extension=com_dotnet
echo extension=curl
echo extension=fileinfo
echo extension=gd
echo extension=openssl
echo extension=intl
echo extension=mbstring
echo extension=mysqli
echo extension=pdo_mysql
echo extension=sqlite3
echo extension=pdo_sqlite
) > release\conf\php-apache2handler.ini
